package com.example.web.dto;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

import io.swagger.annotations.ApiParam;

public class PageQuery {

    @NotNull(message = "{NotNull.pageSize}")
    @Min(value = 1, message = "{Min.pageSize}")
    @ApiParam(value = "pageSize", required = true)
    private Integer pageSize;

    @NotNull(message = "{NotNull.pageIndex}")
    @Min(value = 1, message = "{Min.pageIndex}")
    @ApiParam(value = "pageIndex", required = true)
    private Integer pageIndex;

    private Integer fromIndex;

    public Integer getFromIndex() {
        this.fromIndex = pageSize * (pageIndex - 1);
        return this.fromIndex;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(Integer pageIndex) {
        this.pageIndex = pageIndex;
    }

    @Override
    public String toString() {
        return "PageQuery{" +
                "pageSize=" + pageSize +
                ", pageIndex=" + pageIndex +
                ", fromIndex=" + fromIndex +
                '}';
    }
}
